/**
 * Created by YIJIEDAO2 on 2017/5/30.
 */
import React from 'react';

import Table from '../../../components/table';

import { myFetch } from '../../../utils/func';

const columns = [
  {
    title: 'Name',
    dataIndex: 'name',
    key: 'name'
  }, {
    title: 'money',
    dataIndex: 'money',
    key: 'money',
    sorter: (a, b) => a.money - b.money
  }, {
    title: 'addTime',
    dataIndex: 'addTime',
    key: 'addTime'
  }
];

export default class coupon extends React.Component {

  constructor(props){
    super(props);
    this.state = {
      data:[],
      pagination:{
        total:null,
        pageSize:15,
        showTotal:((total, range)=>{
          return `当前：${range[0]}-${range[1]} 共 ${total} 条数据`
        })
      }
    }
  }

  componentDidMount(){

    let that = this;

    this.props.onFetch();

    myFetch('/Coupon/SearchCouponList',{

    })
      .then(data=>{

        let res = data.data;

        that.setState({
          pagination:{
            total:res.length
          }
        })

        for(let i in res){

          res[i].key = i;

        }

        that.setState({

          data:res

        })

        this.props.afterFetch();

      })

  }

  render(){

    return(

      <div>

        <Table columns={columns} data={this.state.data} pagination={this.state.pagination} loading={this.props.loading}/>

      </div>

    )
  }
}
